package server;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Mapper {

    public List<Host> hostList = new ArrayList<>();

    protected static final class Host {
        private String name; // host名称
        private String appBase; // webapps绝对路径
        public Context[] contexts; // 项目

        public Host(String name, String appBase, Context[] contexts) {
            this.name = name;
            this.appBase = appBase;
            this.contexts = contexts;
        }

        public String getAppBase() {
            return appBase;
        }

        public void setAppBase(String appBase) {
            this.appBase = appBase;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Context[] getContexts() {
            return contexts;
        }

        public void setContexts(Context[] contexts) {
            this.contexts = contexts;
        }

        @Override
        public String toString() {
            return "Host{" +
                    "name='" + name + '\'' +
                    ", appBase='" + appBase + '\'' +
                    ", contexts=" + Arrays.toString(contexts) +
                    '}';
        }
    }

    protected static final class Context {
        public final String name; //项目名
        public final Wrapper[] wrappers; // servlet资源
        public List<String> staticFilePath; // 静态文件绝对路径
        public Context(String name, Wrapper[] wrappers) {
            this.name = name;
            this.wrappers = wrappers;
            staticFilePath = new ArrayList<>();
        }
    }

    //Serlet
    protected static final class Wrapper {
        public final String url; //uri
        public final HttpServlet servlet; //servlet

        public Wrapper(String url, HttpServlet servlet) {
            this.url = url;
            this.servlet = servlet;
        }
    }

}
